package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQueryObject;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/banner")
public class BannerController {


    @Autowired
    private IBannerService bannerService;

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;
    
    
    //列表显示
    @RequestMapping("/list")
    public String list(Model model, BannerQueryObject qo){
        Page<Banner> page = bannerService.query(qo);
        model.addAttribute("page", page);
        model.addAttribute("qo", qo);
        return "/banner/list";
    }

    //获取所有的攻略和游记
    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        //查询所有的攻略
        List<Strategy> sts = strategyService.selectAll();
        //查询所有的游记
        List<Travel> ts = travelService.selectAll();

        Map<String,Object> map=new HashMap<>();
        map.put("sts", sts);
        map.put("ts", ts);
        return JsonResult.success(map);
    }

    //编辑或添加
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        //通过对应的状态查询出对应的数据
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }

    
}
